package com.mobile.learning;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.markupartist.android.widget.ActionBar;
import com.markupartist.android.widget.ActionBar.IntentAction;
import com.mobile.learning.lib.CustomAdapter;
import com.mobile.learning.lib.DBClass;
import com.mobile.learning.lib.Nilai;


import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ListAdapter;

public class HistoryNilaiActivity extends ListActivity{
	public ListAdapter adapter;
	public List<Nilai> dataList;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_history_nilai);

		ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar_post);
		actionBar.setTitle("Nilai");

		actionBar.setHomeAction(new IntentAction(this, MainMenuActivity
				.createIntent(this), R.drawable.ic_action_back));
		
		DBClass db = new DBClass(this);
		ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
		dataList = db.getAllNilai();
		for(Nilai n : dataList){
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("id_nilai", n.getId_nilai());
			map.put("tgl_pengerjaan", n.getTgl_pengerjaan());
			map.put("nama_jenis", n.getSoal());
			map.put("jenis_soal", n.getJenis());
			map.put("nilai", n.getNilai());
			list.add(map);
		}
		adapter = new CustomAdapter(this, list, R.layout.activity_history_nilai_list, new String[] { "id_nilai", "tgl_pengerjaan",
				"nama_jenis", "jenis_soal", "nilai"}, new int[]{ R.id.dt_no, R.id.dt_tanggal, R.id.dt_soal, R.id.dt_jenis, R.id.dt_nilai });
	
		setListAdapter(adapter);
	}
	
	protected void onRestart() {
		super.onRestart();
		startActivity(getIntent());
		finish();

	}

}
